<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
        }
    </style>
</head>
<body>
 <div class="container">
     <div class="row">
         <nav class="navbar navbar-default navbar-static-top">
             <div class="container-fluid">
                 <div class="navbar-header">
                     <a class="navbar-brand" href="../index.html">首页</a>
                 </div>
                 <ul class="nav navbar-nav">
                    <li class="active"><a href="javascript:void(0)">Link</a></li>
                    <li><a href="javascript:void(0)">Link2</a></li>
                 </ul>
             </div>
         </nav>
     </div>
     <h3>AngularJS service数据共享示例</h3>
     <div class="row demo" ng-app="MyAPP">
         <div class="col-md-6" ng-controller="MainCtrl">
             MainCtrl:<input type="text" class="form-control" ng-model="user.name">
         </div>
         <div class="col-md-6" ng-controller="SecondCtrl">
             SecondCtrl:<input type="text" class="form-control" ng-model="user.name">
         </div>
     </div>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script>
    var app=angular.module("MyAPP",[]);
    app.controller('MainCtrl', function($scope, UserInfo) {
        $scope.user = UserInfo;
    });

    app.controller('SecondCtrl', function($scope, UserInfo) {
        $scope.user = UserInfo;
    });

    app.service('UserInfo', function() {
        var user = {
            name: "AngularJS Fans"
        };
        return user;
    });
</script>
